<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<style>
    .level1 {
        width: 50%;
        margin-bottom: 5px;
    }

    .level2 {
        width: 50%;
        float: left;
        margin-bottom: 5px;
    }

    .form-group-col-2 .form-label {
        padding: 3px 0px !important;
        font-size: 12px !important;
        width: 115px;
        font-weight: bolder;
    }

    .form-group-col-2 .form-cont {
        margin-left: 125px;
        min-height: 33px;
    }

    .form-control {
        font-size: 12px !important;
        padding: 4px 15px !important;
    }

    .form-group-col-2 {
        width: 31%;
    }
</style>

<div class="page-wrap">

    <input type="hidden" id="role_check_id" value="${sysid}">
    <c:forEach items="${powers}" var="power">
        <div>
            <div class="form-group-col-2 level1">
                <div class="form-label">${power.sysResourceName}</div>
                <div class="form-cont">
                    <input type="checkbox" id="check_${power.sysid}" pid="0" name="resource_rcheck"
                           value="${power.sysid}" ${power.ishave?'checked':""}>
                </div>
            </div>
            <c:forEach items="${power.childs}" var="child">
                <div class="form-group-col-2 level2">
                    <div class="form-label">${child.sysResourceName}</div>
                    <div class="form-cont">
                        <input type="checkbox" id="rcheck_${child.sysid}" class="check_${power.sysid}"
                               pid="${power.sysid}" name="resource_rcheck"
                               value="${child.sysid}" ${child.ishave?'checked':""}>
                    </div>
                </div>
            </c:forEach>
        </div>
    </c:forEach>

    <div style="clear: both;width: 25%;margin: 10px auto 15px;">
        <button class="btn btn-primary-outline" onclick="savePowers()">保存</button>
    </div>
</div>

<script type="text/javascript">

    $(function () {
        $("input[type=checkbox]").click(function () {
            var id = $(this).attr('value');
            var pid = $(this).attr('pid');
            var flag = $(this).prop('checked');
            if (pid == 0) {
                if (!flag) {
                    $(".check_" + id).each(function (i, obj) {
                        $(obj).prop("checked", false);
                    })
                }
            } else {
                if (flag) {
                    $("#check_" + pid).prop("checked", true);
                }
            }

        })

    });
</script>

